home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 August: Tool Chest / Dev.CD Aug 99 TC.toast / What's New? / Development Kits / Hardware / Mac OS USB DDK v1.3a1 / USB.h < prev   
Encoding:
C/C++ Source or Header  |  1999-06-18  |  35.9 KB  |  1,293 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        USB.h
  3.  
  4.      Contains:    Public API for USB Services Library (and associated components)
  5.  
  6.      Version:    
  7.  
  8. */
  9. #ifndef __USB__
  10. #define __USB__
  11.  
  12. #ifndef __MACTYPES__
  13. #include <MacTypes.h>
  14. #endif
  15.  
  16. #ifndef __NAMEREGISTRY__
  17. #include <NameRegistry.h>
  18. #endif
  19.  
  20. #ifndef __CODEFRAGMENTS__
  21. #include <CodeFragments.h>
  22. #endif
  23.  
  24. #ifndef __DEVICES__
  25. #include <Devices.h>
  26. #endif
  27.  
  28.  
  29.  
  30.  
  31. #if PRAGMA_ONCE
  32. #pragma once
  33. #endif
  34.  
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38.  
  39. #if PRAGMA_IMPORT
  40. #pragma import on
  41. #endif
  42.  
  43. #if PRAGMA_STRUCT_ALIGN
  44.     #pragma options align=mac68k
  45. #elif PRAGMA_STRUCT_PACKPUSH
  46.     #pragma pack(push, 2)
  47. #elif PRAGMA_STRUCT_PACK
  48.     #pragma pack(2)
  49. #endif
  50.  
  51. /* ************* Constants ************* */
  52. enum {
  53.     kUSBNoErr                    = 0,
  54.     kUSBNoTran                    = 0,
  55.     kUSBNoDelay                    = 0,
  56.     kUSBPending                    = 1,                            /* */
  57.                                                                 /* USB assigned error numbers in range -6900 .. -6999 */
  58.     kUSBBaseError                = -7000,                        /* */
  59.                                                                 /* USB Services Errors */
  60.     kUSBInternalErr                = -6999,                        /* Internal error */
  61.     kUSBUnknownDeviceErr        = -6998,                        /*  device ref not recognised */
  62.     kUSBUnknownPipeErr            = -6997,                        /*  Pipe ref not recognised */
  63.     kUSBTooManyPipesErr            = -6996,                        /*  Too many pipes */
  64.     kUSBIncorrectTypeErr        = -6995,                        /*  Incorrect type */
  65.     kUSBRqErr                    = -6994,                        /*  Request error */
  66.     kUSBUnknownRequestErr        = -6993,                        /*  Unknown request */
  67.     kUSBTooManyTransactionsErr    = -6992,                        /*  Too many transactions */
  68.     kUSBAlreadyOpenErr            = -6991,                        /*  Already open */
  69.     kUSBNoDeviceErr                = -6990,                        /*  No device*/
  70.     kUSBDeviceErr                = -6989,                        /*  Device error */
  71.     kUSBOutOfMemoryErr            = -6988,                        /*  Out of memory */
  72.     kUSBNotFound                = -6987,                        /*  Not found */
  73.     kUSBPBVersionError            = -6986,                        /*  Wrong pbVersion */
  74.     kUSBPBLengthError            = -6985,                        /*  pbLength too small */
  75.     kUSBCompletionError            = -6984,                        /*  no completion routine specified */
  76.     kUSBFlagsError                = -6983,                        /*  Unused flags not zeroed */
  77.     kUSBAbortedError            = -6982,                        /*  Pipe aborted */
  78.     kUSBNoBandwidthError        = -6981,                        /*  Not enough bandwidth available */
  79.     kUSBPipeIdleError            = -6980,                        /*  Pipe is Idle, it will not accept transactions */
  80.     kUSBPipeStalledError        = -6979,                        /*  Pipe has stalled, error needs to be cleared */
  81.     kUSBUnknownInterfaceErr        = -6978,                        /*  Interface ref not recognised */
  82.     kUSBDeviceBusy                = -6977,                        /*  Device is already being configured */
  83.     kUSBDevicePowerProblem        = -6976,                        /*  Device has a power problem */
  84.     kUSBInvalidBuffer            = -6975,                        /* bad buffer, usually nil */
  85.     kUSBDeviceSuspended            = -6974,                        /* Device is suspended */
  86.     kUSBDeviceNotSuspended        = -6973,                        /* device is not suspended for resume */
  87.     kUSBDeviceDisconnected        = -6972,                        /* Disconnected during suspend or reset */
  88.                                                                 /* USB internal errors are in range -6960 to -6951*/
  89.                                                                 /* please do not use this range*/
  90.                                                                 /* */
  91.     kUSBInternalReserved1        = -6960,                        /* reserved*/
  92.     kUSBInternalReserved2        = -6959,
  93.     kUSBInternalReserved3        = -6958,
  94.     kUSBInternalReserved4        = -6957,
  95.     kUSBInternalReserved5        = -6956,
  96.     kUSBInternalReserved6        = -6955,
  97.     kUSBInternalReserved7        = -6954,
  98.     kUSBInternalReserved8        = -6953,
  99.     kUSBInternalReserved9        = -6952,
  100.     kUSBInternalReserved10        = -6951,                        /* */
  101.                                                                 /* USB Manager Errors */
  102.     kUSBBadDispatchTable        = -6950,                        /* Improper driver dispatch table     */
  103.     kUSBUnknownNotification        = -6949,                        /* Notification type not defined     */
  104.     kUSBQueueFull                = -6948,                        /* Internal queue maxxed     */
  105.                                                                 /* */
  106.                                                                 /* Hardware Errors */
  107.                                                                 /* Note pipe stalls are communication */
  108.                                                                 /* errors. The affected pipe can not */
  109.                                                                 /* be used until USBClearPipeStallByReference  */
  110.                                                                 /* is used */
  111.                                                                 /* kUSBEndpointStallErr is returned in */
  112.                                                                 /* response to a stall handshake */
  113.                                                                 /* from a device. The device has to be */
  114.                                                                 /* cleared before a USBClearPipeStallByReference */
  115.                                                                 /* can be used */
  116.     kUSBLinkErr                    = -6916,
  117.     kUSBCRCErr                    = -6915,                        /*  Pipe stall, bad CRC */
  118.     kUSBBitstufErr                = -6914,                        /*  Pipe stall, bitstuffing */
  119.     kUSBDataToggleErr            = -6913,                        /*  Pipe stall, Bad data toggle */
  120.     kUSBEndpointStallErr        = -6912,                        /*  Device didn't understand */
  121.     kUSBNotRespondingErr        = -6911,                        /*  Pipe stall, No device, device hung */
  122.     kUSBPIDCheckErr                = -6910,                        /*  Pipe stall, PID CRC error */
  123.     kUSBWrongPIDErr                = -6909,                        /*  Pipe stall, Bad or wrong PID */
  124.     kUSBOverRunErr                = -6908,                        /*  Packet too large or more data than buffer */
  125.     kUSBUnderRunErr                = -6907,                        /*  Less data than buffer */
  126.     kUSBRes1Err                    = -6906,
  127.     kUSBRes2Err                    = -6905,
  128.     kUSBBufOvrRunErr            = -6904,                        /*  Host hardware failure on data in, PCI busy? */
  129.     kUSBBufUnderRunErr            = -6903,                        /*  Host hardware failure on data out, PCI busy? */
  130.     kUSBNotSent1Err                = -6902,                        /*  Transaction not sent */
  131.     kUSBNotSent2Err                = -6901                            /*  Transaction not sent */
  132. };
  133.  
  134. enum {
  135.                                                                 /* Flags */
  136.     kUSBTaskTimeFlag            = 1,
  137.     kUSBHubPower                = 2,
  138.     kUSBPowerReset                = 4,
  139.     kUSBHubReaddress            = 8,
  140.     kUSBAddressRequest            = 16,
  141.     kUSBReturnOnException        = 32,
  142.     kUSBNo5SecTimeout            = 64,
  143.     kUSBTimeout                    = 128
  144. };
  145.  
  146. enum {
  147.                                                                 /* Hub messages */
  148.     kUSBHubPortResetRequest        = 1,
  149.     kUSBHubPortSuspendRequest    = 2
  150. };
  151.  
  152. enum {
  153.     kVendorID_AppleComputer        = 0x05AC
  154. };
  155.  
  156. /* ************* types ************* */
  157.  
  158. typedef SInt32                             USBReference;
  159. typedef USBReference                     USBDeviceRef;
  160. typedef USBDeviceRef *                    USBDeviceRefPtr;
  161. typedef USBReference                     USBInterfaceRef;
  162. typedef USBReference                     USBPipeRef;
  163. typedef USBReference                     USBBusRef;
  164. typedef UInt32                             USBPipeState;
  165. typedef UInt32                             USBCount;
  166. typedef UInt32                             USBFlags;
  167. typedef UInt8                             USBRequest;
  168. typedef UInt8                             USBDirection;
  169. typedef UInt8                             USBRqRecipient;
  170. typedef UInt8                             USBRqType;
  171. typedef UInt16                             USBRqIndex;
  172. typedef UInt16                             USBRqValue;
  173.  
  174.  
  175.  
  176. struct usbControlBits {
  177.     UInt8                             BMRequestType;
  178.     UInt8                             BRequest;
  179.     USBRqValue                         WValue;
  180.     USBRqIndex                         WIndex;
  181.     UInt16                             reserved4;
  182. };
  183. typedef struct usbControlBits            usbControlBits;
  184.  
  185. struct USBIsocFrame {
  186.     OSStatus                         frStatus;
  187.     UInt16                             frReqCount;
  188.     UInt16                             frActCount;
  189. };
  190. typedef struct USBIsocFrame                USBIsocFrame;
  191. enum {
  192.     kUSBMaxIsocFrameReqCount    = 1023                            /* maximum size (bytes) of any one Isoc frame*/
  193. };
  194.  
  195.  
  196. struct usbIsocBits {
  197.     USBIsocFrame *                    FrameList;
  198.     UInt32                             NumFrames;
  199. };
  200. typedef struct usbIsocBits                usbIsocBits;
  201.  
  202. struct usbHubBits {
  203.     UInt32                             Request;
  204.     UInt32                             Spare;
  205. };
  206. typedef struct usbHubBits                usbHubBits;
  207. typedef struct USBPB                     USBPB;
  208. typedef CALLBACK_API_C( void , USBCompletion )(USBPB *pb);
  209.  
  210. union USBVariantBits {
  211.     usbControlBits                     cntl;
  212.     usbIsocBits                     isoc;
  213.     usbHubBits                         hub;
  214. };
  215. typedef union USBVariantBits            USBVariantBits;
  216.  
  217. struct USBPB {
  218.  
  219.     void *                            qlink;
  220.     UInt16                             qType;
  221.     UInt16                             pbLength;
  222.     UInt16                             pbVersion;
  223.     UInt16                             reserved1;
  224.     UInt32                             reserved2;
  225.  
  226.     OSStatus                         usbStatus;
  227.     USBCompletion                     usbCompletion;
  228.     UInt32                             usbRefcon;
  229.  
  230.     USBReference                     usbReference;
  231.  
  232.     void *                            usbBuffer;
  233.     USBCount                         usbReqCount;
  234.     USBCount                         usbActCount;
  235.  
  236.     USBFlags                         usbFlags;
  237.  
  238.     USBVariantBits                     usb;
  239.  
  240.     UInt32                             usbFrame;
  241.  
  242.     UInt8                             usbClassType;
  243.     UInt8                             usbSubclass;
  244.     UInt8                             usbProtocol;
  245.     UInt8                             usbOther;
  246.  
  247.     UInt32                             reserved6;
  248.     UInt16                             reserved7;
  249.     UInt16                             reserved8;
  250.  
  251. };
  252.  
  253.  
  254. typedef USBPB *                            USBPBPtr;
  255. #if !defined(OLDUSBNAMES)
  256. #define OLDUSBNAMES 0
  257. #endif
  258.  
  259. #if OLDUSBNAMES
  260. #define usbBMRequestType  usb.cntl.BMRequestType
  261. #define usbBRequest       usb.cntl.BRequest
  262. #define usbWValue         usb.cntl.WValue
  263. #define usbWIndex         usb.cntl.WIndex
  264. #endif
  265.  
  266. struct uslReq {
  267.     USBDirection                     usbDirection;
  268.     USBRqType                         usbType;
  269.     USBRqRecipient                     usbRecipient;
  270.     USBRequest                         usbRequest;
  271. };
  272. typedef struct uslReq                    uslReq;
  273.  
  274. enum {
  275.                                                                 /* BT 19Aug98, bump up to v1.10 for Isoc*/
  276.     kUSBCurrentPBVersion        = 0x0100,                        /* v1.00*/
  277.     kUSBIsocPBVersion            = 0x0109,                        /* v1.10*/
  278.     kUSBCurrentHubPB            = kUSBIsocPBVersion
  279. };
  280.  
  281.  
  282.  
  283.  
  284. #define kUSBNoCallBack ((USBCompletion)-1L)
  285.  
  286.  
  287. typedef UInt8                             bcdUSB;
  288. enum {
  289.     kUSBControl                    = 0,
  290.     kUSBIsoc                    = 1,
  291.     kUSBBulk                    = 2,
  292.     kUSBInterrupt                = 3,
  293.     kUSBAnyType                    = 0xFF
  294. };
  295.  
  296. /* endpoint type */
  297. enum {
  298.     kUSBOut                        = 0,
  299.     kUSBIn                        = 1,
  300.     kUSBNone                    = 2,
  301.     kUSBAnyDirn                    = 3
  302. };
  303.  
  304. /*USBDirection*/
  305. enum {
  306.     kUSBStandard                = 0,
  307.     kUSBClass                    = 1,
  308.     kUSBVendor                    = 2
  309. };
  310.  
  311. /*USBRqType*/
  312. enum {
  313.     kUSBDevice                    = 0,
  314.     kUSBInterface                = 1,
  315.     kUSBEndpoint                = 2,
  316.     kUSBOther                    = 3
  317. };
  318.  
  319. /*USBRqRecipient*/
  320. enum {
  321.     kUSBRqGetStatus                = 0,
  322.     kUSBRqClearFeature            = 1,
  323.     kUSBRqReserved1                = 2,
  324.     kUSBRqSetFeature            = 3,
  325.     kUSBRqReserved2                = 4,
  326.     kUSBRqSetAddress            = 5,
  327.     kUSBRqGetDescriptor            = 6,
  328.     kUSBRqSetDescriptor            = 7,
  329.     kUSBRqGetConfig                = 8,
  330.     kUSBRqSetConfig                = 9,
  331.     kUSBRqGetInterface            = 10,
  332.     kUSBRqSetInterface            = 11,
  333.     kUSBRqSyncFrame                = 12
  334. };
  335.  
  336. /*USBRequest*/
  337.  
  338. enum {
  339.     kUSBDeviceDesc                = 1,
  340.     kUSBConfDesc                = 2,
  341.     kUSBStringDesc                = 3,
  342.     kUSBInterfaceDesc            = 4,
  343.     kUSBEndpointDesc            = 5,
  344.     kUSBHIDDesc                    = 0x21,
  345.     kUSBReportDesc                = 0x22,
  346.     kUSBPhysicalDesc            = 0x23,
  347.     kUSBHUBDesc                    = 0x29
  348. };
  349.  
  350. /* descriptorType */
  351.  
  352. enum {
  353.     kUSBFeatureDeviceRemoteWakeup = 1,
  354.     kUSBFeatureEndpointStall    = 0
  355. };
  356.  
  357. /* Feature selectors */
  358. enum {
  359.     kUSBActive                    = 0,                            /* Pipe can accept new transactions*/
  360.     kUSBIdle                    = 1,                            /* Pipe will not accept new transactions*/
  361.     kUSBStalled                    = 2,                            /* An error occured on the pipe*/
  362.     kUSBSuspended                = 4                                /* Device is suspended*/
  363. };
  364.  
  365. enum {
  366.     kUSB100mAAvailable            = 50,
  367.     kUSB500mAAvailable            = 250,
  368.     kUSB100mA                    = 50,
  369.     kUSBAtrBusPowered            = 0x80,
  370.     kUSBAtrSelfPowered            = 0x40,
  371.     kUSBAtrRemoteWakeup            = 0x20
  372. };
  373.  
  374. enum {
  375.     kUSBRel10                    = 0x0100
  376. };
  377.  
  378. #define USB_CONSTANT16(x)    ((((x) >> 8) & 0x0ff) | ((x & 0xff) << 8))
  379. enum {
  380.     kUSBDeviceDescriptorLength    = 0x12,
  381.     kUSBInterfaceDescriptorLength = 0x09
  382. };
  383.  
  384.  
  385. struct USBDeviceDescriptor {
  386.     UInt8                             length;
  387.     UInt8                             descType;
  388.     UInt16                             usbRel;
  389.     UInt8                             deviceClass;
  390.     UInt8                             deviceSubClass;
  391.     UInt8                             protocol;
  392.     UInt8                             maxPacketSize;
  393.     UInt16                             vendor;
  394.     UInt16                             product;
  395.     UInt16                             devRel;
  396.     UInt8                             manuIdx;
  397.     UInt8                             prodIdx;
  398.     UInt8                             serialIdx;
  399.     UInt8                             numConf;
  400.     UInt16                             descEnd;                    /* was "end", but this is reserved in some languages*/
  401. };
  402. typedef struct USBDeviceDescriptor        USBDeviceDescriptor;
  403. #ifndef OLDCLASSNAMES
  404. #ifndef __cplusplus
  405. #define class deviceClass
  406. #define subClass deviceSubClass
  407. #endif
  408. #endif
  409. typedef USBDeviceDescriptor *            USBDeviceDescriptorPtr;
  410.  
  411. struct USBDescriptorHeader {
  412.     UInt8                             length;
  413.     UInt8                             descriptorType;
  414. };
  415. typedef struct USBDescriptorHeader        USBDescriptorHeader;
  416. typedef USBDescriptorHeader *            USBDescriptorHeaderPtr;
  417.  
  418. struct USBConfigurationDescriptor {
  419.     UInt8                             length;
  420.     UInt8                             descriptorType;
  421.     UInt16                             totalLength;
  422.     UInt8                             numInterfaces;
  423.     UInt8                             configValue;
  424.     UInt8                             configStrIndex;
  425.     UInt8                             attributes;
  426.     UInt8                             maxPower;
  427. };
  428. typedef struct USBConfigurationDescriptor USBConfigurationDescriptor;
  429. typedef USBConfigurationDescriptor *    USBConfigurationDescriptorPtr;
  430.  
  431. struct USBInterfaceDescriptor {
  432.     UInt8                             length;
  433.     UInt8                             descriptorType;
  434.     UInt8                             interfaceNumber;
  435.     UInt8                             alternateSetting;
  436.     UInt8                             numEndpoints;
  437.     UInt8                             interfaceClass;
  438.     UInt8                             interfaceSubClass;
  439.     UInt8                             interfaceProtocol;
  440.     UInt8                             interfaceStrIndex;
  441. };
  442. typedef struct USBInterfaceDescriptor    USBInterfaceDescriptor;
  443. typedef USBInterfaceDescriptor *        USBInterfaceDescriptorPtr;
  444.  
  445. struct USBEndPointDescriptor {
  446.     UInt8                             length;
  447.     UInt8                             descriptorType;
  448.     UInt8                             endpointAddress;
  449.     UInt8                             attributes;
  450.     UInt16                             maxPacketSize;
  451.     UInt8                             interval;
  452. };
  453. typedef struct USBEndPointDescriptor    USBEndPointDescriptor;
  454. typedef USBEndPointDescriptor *            USBEndPointDescriptorPtr;
  455.  
  456. struct USBHIDDescriptor {
  457.     UInt8                             descLen;
  458.     UInt8                             descType;
  459.     UInt16                             descVersNum;
  460.     UInt8                             hidCountryCode;
  461.     UInt8                             hidNumDescriptors;
  462.     UInt8                             hidDescriptorType;
  463.     UInt8                             hidDescriptorLengthLo;        /* can't make this a single 16bit value or the compiler will add a filler byte*/
  464.     UInt8                             hidDescriptorLengthHi;
  465. };
  466. typedef struct USBHIDDescriptor            USBHIDDescriptor;
  467. typedef USBHIDDescriptor *                USBHIDDescriptorPtr;
  468.  
  469. struct USBHIDReportDesc {
  470.     UInt8                             hidDescriptorType;
  471.     UInt8                             hidDescriptorLengthLo;        /* can't make this a single 16bit value or the compiler will add a filler byte*/
  472.     UInt8                             hidDescriptorLengthHi;
  473. };
  474. typedef struct USBHIDReportDesc            USBHIDReportDesc;
  475. typedef USBHIDReportDesc *                USBHIDReportDescPtr;
  476.  
  477. struct USBHubPortStatus {
  478.     UInt16                             portFlags;                    /* Port status flags */
  479.     UInt16                             portChangeFlags;            /* Port changed flags */
  480. };
  481. typedef struct USBHubPortStatus            USBHubPortStatus;
  482. typedef USBHubPortStatus *                USBHubPortStatusPtr;
  483. /* ********* ProtoTypes *************** */
  484. /* For dealing with endianisms */
  485. EXTERN_API_C( UInt16 )
  486. HostToUSBWord                    (UInt16                 value);
  487.  
  488. EXTERN_API_C( UInt16 )
  489. USBToHostWord                    (UInt16                 value);
  490.  
  491. EXTERN_API_C( UInt32 )
  492. HostToUSBLong                    (UInt32                 value);
  493.  
  494. EXTERN_API_C( UInt32 )
  495. USBToHostLong                    (UInt32                 value);
  496.  
  497. /* Main prototypes */
  498. /* Transfer commands */
  499. EXTERN_API_C( OSStatus )
  500. USBDeviceRequest                (USBPB *                pb);
  501.  
  502. /*extern OSStatus USBOpenPipe(USBPB *pb);*/
  503. EXTERN_API_C( OSStatus )
  504. USBBulkWrite                    (USBPB *                pb);
  505.  
  506. EXTERN_API_C( OSStatus )
  507. USBBulkRead                        (USBPB *                pb);
  508.  
  509. EXTERN_API_C( OSStatus )
  510. USBIntRead                        (USBPB *                pb);
  511.  
  512. EXTERN_API_C( OSStatus )
  513. USBIntWrite                        (USBPB *                pb);
  514.  
  515. EXTERN_API_C( OSStatus )
  516. USBIsocRead                        (USBPB *                pb);
  517.  
  518. EXTERN_API_C( OSStatus )
  519. USBIsocWrite                    (USBPB *                pb);
  520.  
  521. /* Pipe state control */
  522. EXTERN_API_C( OSStatus )
  523. USBClearPipeStallByReference    (USBPipeRef             ref);
  524.  
  525. EXTERN_API_C( OSStatus )
  526. USBAbortPipeByReference            (USBReference             ref);
  527.  
  528. EXTERN_API_C( OSStatus )
  529. USBResetPipeByReference            (USBReference             ref);
  530.  
  531. EXTERN_API_C( OSStatus )
  532. USBSetPipeIdleByReference        (USBPipeRef             ref);
  533.  
  534. EXTERN_API_C( OSStatus )
  535. USBSetPipeActiveByReference        (USBPipeRef             ref);
  536.  
  537. EXTERN_API_C( OSStatus )
  538. USBClosePipeByReference            (USBPipeRef             ref);
  539.  
  540. EXTERN_API_C( OSStatus )
  541. USBGetPipeStatusByReference        (USBReference             ref,
  542.                                  USBPipeState *            state);
  543.  
  544.  
  545. /* Configuration services */
  546. EXTERN_API_C( OSStatus )
  547. USBFindNextInterface            (USBPB *                pb);
  548.  
  549. EXTERN_API_C( OSStatus )
  550. USBOpenDevice                    (USBPB *                pb);
  551.  
  552. EXTERN_API_C( OSStatus )
  553. USBSetConfiguration                (USBPB *                pb);
  554.  
  555. EXTERN_API_C( OSStatus )
  556. USBNewInterfaceRef                (USBPB *                pb);
  557.  
  558. EXTERN_API_C( OSStatus )
  559. USBDisposeInterfaceRef            (USBPB *                pb);
  560.  
  561. EXTERN_API_C( OSStatus )
  562. USBConfigureInterface            (USBPB *                pb);
  563.  
  564. EXTERN_API_C( OSStatus )
  565. USBFindNextPipe                    (USBPB *                pb);
  566.  
  567.  
  568. /* Dealing with descriptors. */
  569. /* Note most of this is temprorary */
  570. EXTERN_API_C( OSStatus )
  571. USBGetConfigurationDescriptor    (USBPB *                pb);
  572.  
  573. EXTERN_API_C( OSStatus )
  574. USBGetFullConfigurationDescriptor (USBPB *                pb);
  575.  
  576. EXTERN_API_C( OSStatus )
  577. USBFindNextEndpointDescriptorImmediate (USBPB *            pb);
  578.  
  579. EXTERN_API_C( OSStatus )
  580. USBFindNextInterfaceDescriptorImmediate (USBPB *        pb);
  581.  
  582. EXTERN_API_C( OSStatus )
  583. USBFindNextAssociatedDescriptor    (USBPB *                pb);
  584.  
  585.  
  586.  
  587. /* Utility functions */
  588. EXTERN_API_C( OSStatus )
  589. USBResetDevice                    (USBPB *                pb);
  590.  
  591. EXTERN_API_C( OSStatus )
  592. USBSuspendDevice                (USBPB *                pb);
  593.  
  594. EXTERN_API_C( OSStatus )
  595. USBResumeDeviceByReference        (USBReference             refIn);
  596.  
  597. EXTERN_API_C( OSStatus )
  598. USBGetFrameNumberImmediate        (USBPB *                pb);
  599.  
  600. EXTERN_API_C( OSStatus )
  601. USBDelay                        (USBPB *                pb);
  602.  
  603. EXTERN_API_C( OSStatus )
  604. USBSAbortQueuesByReference        (USBReference             ref);
  605.  
  606. EXTERN_API_C( OSStatus )
  607. USBAllocMem                        (USBPB *                pb);
  608.  
  609. EXTERN_API_C( OSStatus )
  610. USBDeallocMem                    (USBPB *                pb);
  611.  
  612. /* Expert interface functions */
  613. EXTERN_API_C( OSStatus )
  614. USBExpertInstallInterfaceDriver    (USBDeviceRef             ref,
  615.                                  USBDeviceDescriptorPtr  desc,
  616.                                  USBInterfaceDescriptorPtr  interfacePtr,
  617.                                  USBReference             hubRef,
  618.                                  UInt32                 busPowerAvailable);
  619.  
  620. EXTERN_API_C( OSStatus )
  621. USBExpertRemoveInterfaceDriver    (USBDeviceRef             ref);
  622.  
  623. EXTERN_API_C( OSStatus )
  624. USBExpertInstallDeviceDriver    (USBDeviceRef             ref,
  625.                                  USBDeviceDescriptorPtr  desc,
  626.                                  USBReference             hubRef,
  627.                                  UInt32                 port,
  628.                                  UInt32                 busPowerAvailable);
  629.  
  630. EXTERN_API_C( OSStatus )
  631. USBExpertRemoveDeviceDriver        (USBDeviceRef             ref);
  632.  
  633. EXTERN_API_C( OSStatus )
  634. USBExpertStatus                    (USBDeviceRef             ref,
  635.                                  void *                    pointer,
  636.                                  UInt32                 value);
  637.  
  638. EXTERN_API_C( OSStatus )
  639. USBExpertFatalError                (USBDeviceRef             ref,
  640.                                  OSStatus                 status,
  641.                                  void *                    pointer,
  642.                                  UInt32                 value);
  643.  
  644. EXTERN_API_C( OSStatus )
  645. USBExpertNotify                    (void *                    note);
  646.  
  647. EXTERN_API_C( OSStatus )
  648. USBExpertStatusLevel            (UInt32                 level,
  649.                                  USBDeviceRef             ref,
  650.                                  StringPtr                 status,
  651.                                  UInt32                 value);
  652.  
  653. EXTERN_API_C( UInt32 )
  654. USBExpertGetStatusLevel            (void);
  655.  
  656. EXTERN_API_C( void )
  657. USBExpertSetStatusLevel            (UInt32                 level);
  658.  
  659.  
  660.  
  661. EXTERN_API_C( OSStatus )
  662. USBExpertSetDevicePowerStatus    (USBDeviceRef             ref,
  663.                                  UInt32                 reserved1,
  664.                                  UInt32                 reserved2,
  665.                                  UInt32                 powerStatus,
  666.                                  UInt32                 busPowerAvailable,
  667.                                  UInt32                 busPowerNeeded);
  668.  
  669. enum {
  670.     kUSBDevicePower_PowerOK        = 0,
  671.     kUSBDevicePower_BusPowerInsufficient = 1,
  672.     kUSBDevicePower_BusPowerNotAllFeatures = 2,
  673.     kUSBDevicePower_SelfPowerInsufficient = 3,
  674.     kUSBDevicePower_SelfPowerNotAllFeatures = 4,
  675.     kUSBDevicePower_HubPortOk    = 5,
  676.     kUSBDevicePower_HubPortOverCurrent = 6,
  677.     kUSBDevicePower_BusPoweredHubOnLowPowerPort = 7,
  678.     kUSBDevicePower_BusPoweredHubToBusPoweredHub = 8,
  679.     kUSBDevicePower_Reserved3    = 9,
  680.     kUSBDevicePower_Reserved4    = 10
  681. };
  682.  
  683.  
  684. /* For hubs only */
  685. EXTERN_API_C( OSStatus )
  686. USBHubAddDevice                    (USBPB *                pb);
  687.  
  688. EXTERN_API_C( OSStatus )
  689. USBHubConfigurePipeZero            (USBPB *                pb);
  690.  
  691. EXTERN_API_C( OSStatus )
  692. USBHubSetAddress                (USBPB *                pb);
  693.  
  694. EXTERN_API_C( OSStatus )
  695. USBHubDeviceRemoved                (USBPB *                pb);
  696.  
  697.  
  698. EXTERN_API_C( UInt8 )
  699. USBMakeBMRequestType            (UInt8                     direction,
  700.                                  UInt8                     reqtype,
  701.                                  UInt8                     recipient);
  702.  
  703. EXTERN_API_C( OSStatus )
  704. USBControlRequest                (USBPB *                pb);
  705.  
  706.  
  707. typedef UInt32                             USBLocationID;
  708. enum {
  709.     kUSBLocationNibbleFormat    = 0                                /* Other values are reserved for future types (like when we have more than 16 ports per hub)*/
  710. };
  711.  
  712.  
  713. enum {
  714.     kNoDeviceRef                = -1
  715. };
  716.  
  717. /* Status Level constants*/
  718. /*
  719. Level 1: Fatal errors
  720. Level 2: General errors that may or may not effect operation
  721. Level 3: General driver messages.  The "AddStatus" call that drivers use comes through as a level 3.  This is also the default level at boot time.
  722. Level 4: Important status messages from the Expert and USL.
  723. Level 5: General status messages from the Expert and USL.
  724. */
  725. enum {
  726.     kUSBStatusLevelFatal        = 1,
  727.     kUSBStatusLevelError        = 2,
  728.     kUSBStatusLevelClient        = 3,
  729.     kUSBStatusLevelGeneral        = 4,
  730.     kUSBStatusLevelVerbose        = 5
  731. };
  732.  
  733. /* Expert Notification Types*/
  734. typedef UInt8                             USBNotificationType;
  735. typedef UInt8                             USBDriverMessage;
  736. enum {
  737.     kNotifyAddDevice            = 0x00,
  738.     kNotifyRemoveDevice            = 0x01,
  739.     kNotifyAddInterface            = 0x02,
  740.     kNotifyRemoveInterface        = 0x03,
  741.     kNotifyGetDeviceDescriptor    = 0x04,
  742.     kNotifyGetInterfaceDescriptor = 0x05,
  743.     kNotifyGetNextDeviceByClass    = 0x06,
  744.     kNotifyGetDriverConnectionID = 0x07,
  745.     kNotifyInstallDeviceNotification = 0x08,
  746.     kNotifyRemoveDeviceNotification = 0x09,
  747.     kNotifyDeviceRefToBusRef    = 0x0A,
  748.     kNotifyDriverNotify            = 0x0C,
  749.     kNotifyParentNotify            = 0x0D,
  750.     kNotifyAnyEvent                = 0xFF,
  751.     kNotifyPowerState            = 0x17,
  752.     kNotifyStatus                = 0x18,
  753.     kNotifyFatalError            = 0x19,
  754.     kNotifyStatusLevel            = 0x20
  755. };
  756.  
  757. /*
  758.    USB Manager wildcard constants for USBGetNextDeviceByClass
  759.    and USBInstallDeviceNotification.
  760. */
  761. typedef UInt16                             USBManagerWildcard;
  762. enum {
  763.     kUSBAnyClass                = 0xFFFF,
  764.     kUSBAnySubClass                = 0xFFFF,
  765.     kUSBAnyProtocol                = 0xFFFF,
  766.     kUSBAnyVendor                = 0xFFFF,
  767.     kUSBAnyProduct                = 0xFFFF
  768. };
  769.  
  770.  
  771.  
  772.  
  773. struct ExpertNotificationData {
  774.     USBNotificationType             notification;
  775.     UInt8                             filler[1];                    /* unused due to 2-byte 68k alignment*/
  776.     USBDeviceRef *                    deviceRef;
  777.     UInt32                             busPowerAvailable;
  778.     void *                            data;
  779.     UInt32                             info1;
  780.     UInt32                             info2;
  781. };
  782. typedef struct ExpertNotificationData    ExpertNotificationData;
  783. typedef ExpertNotificationData *        ExpertNotificationDataPtr;
  784. /* Definition of function pointer passed in ExpertEntryProc*/
  785. typedef CALLBACK_API_C( OSStatus , ExpertNotificationProcPtr )(ExpertNotificationDataPtr pNotificationData);
  786. /* Definition of expert's callback installation function*/
  787. typedef CALLBACK_API_C( OSStatus , ExpertEntryProcPtr )(ExpertNotificationProcPtr pExpertNotify);
  788. /* Device Notification Callback Routine*/
  789. typedef CALLBACK_API_C( void , USBDeviceNotificationCallbackProcPtr )(void *pb);
  790. /* Device Notification Parameter Block*/
  791.  
  792. struct USBDeviceNotificationParameterBlock {
  793.     UInt16                             pbLength;
  794.     UInt16                             pbVersion;
  795.     USBNotificationType             usbDeviceNotification;
  796.     UInt8                             reserved1[1];                /* needed because of 2-byte 68k alignment*/
  797.     USBDeviceRef                     usbDeviceRef;
  798.     UInt16                             usbClass;
  799.     UInt16                             usbSubClass;
  800.     UInt16                             usbProtocol;
  801.     UInt16                             usbVendor;
  802.     UInt16                             usbProduct;
  803.     OSStatus                         result;
  804.     UInt32                             token;
  805.     USBDeviceNotificationCallbackProcPtr  callback;
  806.     UInt32                             refcon;
  807. };
  808. typedef struct USBDeviceNotificationParameterBlock USBDeviceNotificationParameterBlock;
  809. typedef USBDeviceNotificationParameterBlock * USBDeviceNotificationParameterBlockPtr;
  810. /* Definition of USBDriverNotificationCallback Routine*/
  811. typedef CALLBACK_API_C( void , USBDriverNotificationCallbackPtr )(OSStatus status, UInt32 refcon);
  812. /* Public Functions*/
  813. EXTERN_API_C( OSStatus )
  814. USBGetNextDeviceByClass            (USBDeviceRef *            deviceRef,
  815.                                  CFragConnectionID *    connID,
  816.                                  UInt16                 theClass,
  817.                                  UInt16                 theSubClass,
  818.                                  UInt16                 theProtocol);
  819.  
  820. EXTERN_API_C( OSStatus )
  821. USBGetDeviceDescriptor            (USBDeviceRef *            deviceRef,
  822.                                  USBDeviceDescriptor *    deviceDescriptor,
  823.                                  UInt32                 size);
  824.  
  825. EXTERN_API_C( OSStatus )
  826. USBGetInterfaceDescriptor        (USBInterfaceRef *        interfaceRef,
  827.                                  USBInterfaceDescriptor * interfaceDescriptor,
  828.                                  UInt32                 size);
  829.  
  830. EXTERN_API_C( OSStatus )
  831. USBGetDriverConnectionID        (USBDeviceRef *            deviceRef,
  832.                                  CFragConnectionID *    connID);
  833.  
  834. EXTERN_API_C( void )
  835. USBInstallDeviceNotification    (USBDeviceNotificationParameterBlock * pb);
  836.  
  837. EXTERN_API_C( OSStatus )
  838. USBRemoveDeviceNotification        (UInt32                 token);
  839.  
  840. EXTERN_API_C( OSStatus )
  841. USBDeviceRefToBusRef            (USBDeviceRef *            deviceRef,
  842.                                  USBBusRef *            busRef);
  843.  
  844. EXTERN_API_C( OSStatus )
  845. USBDriverNotify                    (USBReference             reference,
  846.                                  USBDriverMessage         mesg,
  847.                                  UInt32                 refcon,
  848.                                  USBDriverNotificationCallbackPtr  callback);
  849.  
  850. EXTERN_API_C( OSStatus )
  851. USBExpertNotifyParent            (USBReference             reference,
  852.                                  void *                    pointer);
  853.  
  854. EXTERN_API_C( OSStatus )
  855. USBAddShimFromDisk                (FSSpec *                shimFilePtr);
  856.  
  857. typedef CALLBACK_API_C( void , HIDInterruptProcPtr )(UInt32 refcon, void *theData);
  858. typedef CALLBACK_API_C( void , HIDNotificationProcPtr )(UInt32 refcon, UInt32 reportSize, void *theReport, USBReference theInterfaceRef);
  859. /* HID Install Interrupt prototype*/
  860. typedef CALLBACK_API_C( OSStatus , USBHIDInstallInterruptProcPtr )(HIDInterruptProcPtr pInterruptProc, UInt32 refcon);
  861. /* HID Poll Device prototype*/
  862. typedef CALLBACK_API_C( OSStatus , USBHIDPollDeviceProcPtr )(void );
  863. /* HID Control Device prototype*/
  864. typedef CALLBACK_API_C( OSStatus , USBHIDControlDeviceProcPtr )(UInt32 theControlSelector, void *theControlData);
  865. /* HID Get Device Info prototype*/
  866. typedef CALLBACK_API_C( OSStatus , USBHIDGetDeviceInfoProcPtr )(UInt32 theInfoSelector, void *theInfo);
  867. /* HID Enter Polled Mode prototype*/
  868. typedef CALLBACK_API_C( OSStatus , USBHIDEnterPolledModeProcPtr )(void );
  869. /* HID Exit Polled Mode prototype*/
  870. typedef CALLBACK_API_C( OSStatus , USBHIDExitPolledModeProcPtr )(void );
  871. /* HID Install Notification prototype*/
  872. typedef CALLBACK_API_C( OSStatus , USBHIDInstallNotificationProcPtr )(HIDNotificationProcPtr pNotificationProc, UInt32 refcon);
  873. enum {
  874.     kHIDStandardDispatchVersion    = 0,
  875.     kHIDReservedDispatchVersion    = 1,
  876.     kHIDNotificationDispatchVersion = 2,
  877.     kHIDCurrentDispatchVersion    = 2
  878. };
  879.  
  880.  
  881.  
  882. struct USBHIDRev2DispatchTable {
  883.     UInt32                             hidDispatchVersion;
  884.     USBHIDInstallInterruptProcPtr     pUSBHIDInstallInterrupt;
  885.     USBHIDPollDeviceProcPtr         pUSBHIDPollDevice;
  886.     USBHIDControlDeviceProcPtr         pUSBHIDControlDevice;
  887.     USBHIDGetDeviceInfoProcPtr         pUSBHIDGetDeviceInfo;
  888.     USBHIDEnterPolledModeProcPtr     pUSBHIDEnterPolledMode;
  889.     USBHIDExitPolledModeProcPtr     pUSBHIDExitPolledMode;
  890.     USBHIDInstallNotificationProcPtr  pUSBHIDInstallNotification;
  891. };
  892. typedef struct USBHIDRev2DispatchTable    USBHIDRev2DispatchTable;
  893. typedef USBHIDRev2DispatchTable *        USBHIDRev2DispatchTablePtr;
  894.  
  895. struct USBHIDModuleDispatchTable {
  896.     UInt32                             hidDispatchVersion;
  897.     USBHIDInstallInterruptProcPtr     pUSBHIDInstallInterrupt;
  898.     USBHIDPollDeviceProcPtr         pUSBHIDPollDevice;
  899.     USBHIDControlDeviceProcPtr         pUSBHIDControlDevice;
  900.     USBHIDGetDeviceInfoProcPtr         pUSBHIDGetDeviceInfo;
  901.     USBHIDEnterPolledModeProcPtr     pUSBHIDEnterPolledMode;
  902.     USBHIDExitPolledModeProcPtr     pUSBHIDExitPolledMode;
  903. };
  904. typedef struct USBHIDModuleDispatchTable USBHIDModuleDispatchTable;
  905. typedef USBHIDModuleDispatchTable *        USBHIDModuleDispatchTablePtr;
  906. /*    Prototypes Tue, Mar 17, 1998 4:54:30 PM    */
  907. EXTERN_API_C( OSStatus )
  908. USBHIDInstallInterrupt            (HIDInterruptProcPtr     HIDInterruptFunction,
  909.                                  UInt32                 refcon);
  910.  
  911. EXTERN_API_C( OSStatus )
  912. USBHIDPollDevice                (void);
  913.  
  914. EXTERN_API_C( OSStatus )
  915. USBHIDControlDevice                (UInt32                 theControlSelector,
  916.                                  void *                    theControlData);
  917.  
  918. EXTERN_API_C( OSStatus )
  919. USBHIDGetDeviceInfo                (UInt32                 theInfoSelector,
  920.                                  void *                    theInfo);
  921.  
  922. EXTERN_API_C( OSStatus )
  923. USBHIDEnterPolledMode            (void);
  924.  
  925. EXTERN_API_C( OSStatus )
  926. USBHIDExitPolledMode            (void);
  927.  
  928. EXTERN_API_C( OSStatus )
  929. USBHIDInstallNotification        (HIDNotificationProcPtr  HIDNotificationFunction,
  930.                                  UInt32                 refcon);
  931.  
  932. EXTERN_API_C( void )
  933. HIDNotification                    (UInt32                 devicetype,
  934.                                  UInt8                     NewHIDData[],
  935.                                  UInt8                     OldHIDData[]);
  936.  
  937. enum {
  938.     kHIDRqGetReport                = 1,
  939.     kHIDRqGetIdle                = 2,
  940.     kHIDRqGetProtocol            = 3,
  941.     kHIDRqSetReport                = 9,
  942.     kHIDRqSetIdle                = 10,
  943.     kHIDRqSetProtocol            = 11
  944. };
  945.  
  946. enum {
  947.     kHIDRtInputReport            = 1,
  948.     kHIDRtOutputReport            = 2,
  949.     kHIDRtFeatureReport            = 3
  950. };
  951.  
  952. enum {
  953.     kHIDBootProtocolValue        = 0,
  954.     kHIDReportProtocolValue        = 1
  955. };
  956.  
  957. enum {
  958.     kHIDKeyboardInterfaceProtocol = 1,
  959.     kHIDMouseInterfaceProtocol    = 2
  960. };
  961.  
  962. enum {
  963.     kHIDSetLEDStateByBits        = 1,
  964.     kHIDSetLEDStateByBitMask    = 1,
  965.     kHIDSetLEDStateByIDNumber    = 2,
  966.     kHIDRemoveInterruptHandler    = 3,
  967.     kHIDEnableDemoMode            = 4,
  968.     kHIDDisableDemoMode            = 5,
  969.     kHIDRemoveNotification        = 0x1000
  970. };
  971.  
  972. enum {
  973.     kHIDGetLEDStateByBits        = 1,                            /* not supported in 1.0 of keyboard module*/
  974.     kHIDGetLEDStateByBitMask    = 1,                            /* not supported in 1.0 of keyboard module*/
  975.     kHIDGetLEDStateByIDNumber    = 2,
  976.     kHIDGetDeviceCountryCode    = 3,                            /* not supported in 1.0 HID modules*/
  977.     kHIDGetDeviceUnitsPerInch    = 4,                            /* only supported in mouse HID module*/
  978.     kHIDGetInterruptHandler        = 5,
  979.     kHIDGetCurrentKeys            = 6,                            /* only supported in keyboard HID module*/
  980.     kHIDGetInterruptRefcon        = 7,
  981.     kHIDGetVendorID                = 8,
  982.     kHIDGetProductID            = 9
  983. };
  984.  
  985.  
  986. enum {
  987.     kNumLockLED                    = 0,
  988.     kCapsLockLED                = 1,
  989.     kScrollLockLED                = 2,
  990.     kComposeLED                    = 3,
  991.     kKanaLED                    = 4
  992. };
  993.  
  994. enum {
  995.     kNumLockLEDMask                = 1 << kNumLockLED,
  996.     kCapsLockLEDMask            = 1 << kCapsLockLED,
  997.     kScrollLockLEDMask            = 1 << kScrollLockLED,
  998.     kComposeLEDMask                = 1 << kComposeLED,
  999.     kKanaLEDMask                = 1 << kKanaLED
  1000. };
  1001.  
  1002. enum {
  1003.     kUSBCapsLockKey                = 0x39,
  1004.     kUSBNumLockKey                = 0x53,
  1005.     kUSBScrollLockKey            = 0x47
  1006. };
  1007.  
  1008.  
  1009. struct USBMouseData {
  1010.     UInt16                             buttons;
  1011.     SInt16                             XDelta;
  1012.     SInt16                             YDelta;
  1013. };
  1014. typedef struct USBMouseData                USBMouseData;
  1015. typedef USBMouseData *                    USBMouseDataPtr;
  1016.  
  1017. struct USBKeyboardData {
  1018.     UInt16                             keycount;
  1019.     UInt16                             usbkeycode[32];
  1020. };
  1021. typedef struct USBKeyboardData            USBKeyboardData;
  1022. typedef USBKeyboardData *                USBKeyboardDataPtr;
  1023.  
  1024. union USBHIDData {
  1025.     USBKeyboardData                 kbd;
  1026.     USBMouseData                     mouse;
  1027. };
  1028. typedef union USBHIDData                USBHIDData;
  1029. typedef USBHIDData *                    USBHIDDataPtr;
  1030. EXTERN_API_C( void )
  1031. StartCompoundClassDriver        (USBDeviceRef             device,
  1032.                                  UInt16                 classID,
  1033.                                  UInt16                 subClass);
  1034.  
  1035. enum {
  1036.     kUSBCompositeClass            = 0,
  1037.     kUSBAudioClass                = 1,
  1038.     kUSBCommClass                = 2,
  1039.     kUSBHIDClass                = 3,
  1040.     kUSBDisplayClass            = 4,
  1041.     kUSBPrintingClass            = 7,
  1042.     kUSBMassStorageClass        = 8,
  1043.     kUSBHubClass                = 9,
  1044.     kUSBDataClass                = 10,
  1045.     kUSBVendorSpecificClass        = 0xFF
  1046. };
  1047.  
  1048. enum {
  1049.     kUSBCompositeSubClass        = 0,
  1050.     kUSBHubSubClass                = 1,
  1051.     kUSBPrinterSubclass            = 1,
  1052.     kUSBVendorSpecificSubClass    = 0xFF
  1053. };
  1054.  
  1055. enum {
  1056.     kUSBHIDInterfaceClass        = 0x03
  1057. };
  1058.  
  1059. enum {
  1060.     kUSBNoInterfaceSubClass        = 0x00,
  1061.     kUSBBootInterfaceSubClass    = 0x01
  1062. };
  1063.  
  1064. enum {
  1065.     kUSBNoInterfaceProtocol        = 0x00,
  1066.     kUSBKeyboardInterfaceProtocol = 0x01,
  1067.     kUSBMouseInterfaceProtocol    = 0x02,
  1068.     kUSBVendorSpecificProtocol    = 0xFF
  1069. };
  1070.  
  1071. enum {
  1072.     kUSBPrinterUnidirectionalProtocol = 0x01,
  1073.     kUSBPrinterBidirectionalProtocol = 0x02
  1074. };
  1075.  
  1076.  
  1077. enum {
  1078.     kServiceCategoryUSB            = FOUR_CHAR_CODE('usb ')        /* USB*/
  1079. };
  1080.  
  1081. /* SOMETHING NEEDS TO BE DONE WITH THIS - */
  1082. enum {
  1083.     kUSBTypeIsHub                = FOUR_CHAR_CODE('hubd'),        /* Hub*/
  1084.     kUSBTypeIsHID                = FOUR_CHAR_CODE('HIDd'),        /* Human Interface Device*/
  1085.     kUSBTypeIsDisplay            = FOUR_CHAR_CODE('disp'),        /* Display */
  1086.     kUSBTypeIsModem                = FOUR_CHAR_CODE('modm')        /* Modem*/
  1087. };
  1088.  
  1089. enum {
  1090.     kUSBDriverFileType            = FOUR_CHAR_CODE('ndrv'),
  1091.     kUSBDriverRsrcType            = FOUR_CHAR_CODE('usbd'),
  1092.     kUSBShimRsrcType            = FOUR_CHAR_CODE('usbs')
  1093. };
  1094.  
  1095. enum {
  1096.     kTheUSBDriverDescriptionSignature = FOUR_CHAR_CODE('usbd')
  1097. };
  1098.  
  1099. enum {
  1100.     kInitialUSBDriverDescriptor    = 0
  1101. };
  1102.  
  1103.  
  1104.  
  1105. typedef UInt32                             USBDriverDescVersion;
  1106. /*  Driver Loading Options*/
  1107. typedef UInt32                             USBDriverLoadingOptions;
  1108. enum {
  1109.     kUSBDoNotMatchGenericDevice    = 0x00000001,                    /* Driver's VendorID must match Device's VendorID*/
  1110.     kUSBDoNotMatchInterface        = 0x00000002,                    /* Do not load this driver as an interface driver.*/
  1111.     kUSBProtocolMustMatch        = 0x00000004,                    /* Do not load this driver if protocol field doesn't match.*/
  1112.     kUSBInterfaceMatchOnly        = 0x00000008                    /* Only load this driver as an interface driver.*/
  1113. };
  1114.  
  1115. enum {
  1116.     kClassDriverPluginVersion    = 0x00001100
  1117. };
  1118.  
  1119.  
  1120.  
  1121.  
  1122. struct USBDeviceInfo {
  1123.     UInt16                             usbVendorID;                /* USB Vendor ID*/
  1124.     UInt16                             usbProductID;                /* USB Product ID.*/
  1125.     UInt16                             usbDeviceReleaseNumber;        /* Release Number of Device*/
  1126.     UInt16                             usbDeviceProtocol;            /* Protocol Info.*/
  1127. };
  1128. typedef struct USBDeviceInfo            USBDeviceInfo;
  1129. typedef USBDeviceInfo *                    USBDeviceInfoPtr;
  1130.  
  1131. struct USBInterfaceInfo {
  1132.     UInt8                             usbConfigValue;                /* Configuration Value*/
  1133.     UInt8                             usbInterfaceNum;            /* Interface Number*/
  1134.     UInt8                             usbInterfaceClass;            /* Interface Class*/
  1135.     UInt8                             usbInterfaceSubClass;        /* Interface SubClass*/
  1136.     UInt8                             usbInterfaceProtocol;        /* Interface Protocol*/
  1137. };
  1138. typedef struct USBInterfaceInfo            USBInterfaceInfo;
  1139. typedef USBInterfaceInfo *                USBInterfaceInfoPtr;
  1140.  
  1141. struct USBDriverType {
  1142.     Str31                             nameInfoStr;                /* Driver's name when loading into the Name Registry.*/
  1143.     UInt8                             usbDriverClass;                /* USB Class this driver belongs to.*/
  1144.     UInt8                             usbDriverSubClass;            /* Module type*/
  1145.     NumVersion                         usbDriverVersion;            /* Class driver version number.*/
  1146. };
  1147. typedef struct USBDriverType            USBDriverType;
  1148. typedef USBDriverType *                    USBDriverTypePtr;
  1149.  
  1150. struct USBDriverDescription {
  1151.     OSType                             usbDriverDescSignature;        /* Signature field of this structure.*/
  1152.     USBDriverDescVersion             usbDriverDescVersion;        /* Version of this data structure.*/
  1153.     USBDeviceInfo                     usbDeviceInfo;                /* Product & Vendor Info*/
  1154.     USBInterfaceInfo                 usbInterfaceInfo;            /* Interface info*/
  1155.     USBDriverType                     usbDriverType;                /* Driver Info.*/
  1156.     USBDriverLoadingOptions         usbDriverLoadingOptions;    /* Options for class driver loading.*/
  1157. };
  1158. typedef struct USBDriverDescription        USBDriverDescription;
  1159. typedef USBDriverDescription *            USBDriverDescriptionPtr;
  1160. /*
  1161.    Dispatch Table
  1162.    Definition of class driver's HW Validation proc.
  1163. */
  1164. typedef CALLBACK_API_C( OSStatus , USBDValidateHWProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  1165. /*
  1166.    Definition of class driver's device initialization proc.
  1167.    Called if the driver is being loaded for a device
  1168. */
  1169. typedef CALLBACK_API_C( OSStatus , USBDInitializeDeviceProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable);
  1170. /* Definition of class driver's interface initialization proc.*/
  1171. typedef CALLBACK_API_C( OSStatus , USBDInitializeInterfaceProcPtr )(UInt32 interfaceNum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDevice, USBInterfaceRef interfaceRef);
  1172. /* Definition of class driver's finalization proc.*/
  1173. typedef CALLBACK_API_C( OSStatus , USBDFinalizeProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  1174.  
  1175. typedef UInt32                             USBDriverNotification;
  1176. enum {
  1177.     kNotifySystemSleepRequest    = 0x00000001,
  1178.     kNotifySystemSleepDemand    = 0x00000002,
  1179.     kNotifySystemSleepWakeUp    = 0x00000003,
  1180.     kNotifySystemSleepRevoke    = 0x00000004,
  1181.     kNotifyHubEnumQuery            = 0x00000006,
  1182.     kNotifyChildMessage            = 0x00000007,
  1183.     kNotifyExpertTerminating    = 0x00000008,
  1184.     kNotifyDriverBeingRemoved    = 0x0000000B
  1185. };
  1186.  
  1187. /*
  1188.    Definition of driver's notificatipn proc.      
  1189.    Added refcon for 1.1 version of dispatch table
  1190. */
  1191. typedef CALLBACK_API_C( OSStatus , USBDDriverNotifyProcPtr )(USBDriverNotification notification, void *pointer, UInt32 refcon);
  1192.  
  1193. struct USBClassDriverPluginDispatchTable {
  1194.     UInt32                             pluginVersion;
  1195.     USBDValidateHWProcPtr             validateHWProc;                /* Proc for driver to verify proper HW*/
  1196.     USBDInitializeDeviceProcPtr     initializeDeviceProc;        /* Proc that initializes the class driver.*/
  1197.     USBDInitializeInterfaceProcPtr     initializeInterfaceProc;    /* Proc that initializes a particular interface in the class driver.*/
  1198.     USBDFinalizeProcPtr             finalizeProc;                /* Proc that finalizes the class driver.*/
  1199.     USBDDriverNotifyProcPtr         notificationProc;            /* Proc to pass notifications to the driver.*/
  1200. };
  1201. typedef struct USBClassDriverPluginDispatchTable USBClassDriverPluginDispatchTable;
  1202. typedef USBClassDriverPluginDispatchTable * USBClassDriverPluginDispatchTablePtr;
  1203. /* Hub defines*/
  1204.  
  1205.  
  1206. enum {
  1207.     kUSBHubDescriptorType        = 0x29
  1208. };
  1209.  
  1210. enum {
  1211.                                                                 /* Hub features */
  1212.     kUSBHubLocalPowerChangeFeature = 0,
  1213.     kUSBHubOverCurrentChangeFeature = 1,                        /* port features */
  1214.     kUSBHubPortConnectionFeature = 0,
  1215.     kUSBHubPortEnablenFeature    = 1,
  1216.     kUSBHubPortSuspecdFeature    = 2,
  1217.     kUSBHubPortOverCurrentFeature = 3,
  1218.     kUSBHubPortResetFeature        = 4,
  1219.     kUSBHubPortPowerFeature        = 8,
  1220.     kUSBHubPortLowSpeedFeature    = 9,
  1221.     kUSBHubPortConnectionChangeFeature = 16,
  1222.     kUSBHubPortEnableChangeFeature = 17,
  1223.     kUSBHubPortSuspendChangeFeature = 18,
  1224.     kUSBHubPortOverCurrentChangeFeature = 19,
  1225.     kUSBHubPortResetChangeFeature = 20
  1226. };
  1227.  
  1228.  
  1229. enum {
  1230.     kHubPortConnection            = 1,
  1231.     kHubPortEnabled                = 2,
  1232.     kHubPortSuspend                = 4,
  1233.     kHubPortOverCurrent            = 8,
  1234.     kHubPortBeingReset            = 16,
  1235.     kHubPortPower                = 0x0100,
  1236.     kHubPortSpeed                = 0x0200
  1237. };
  1238.  
  1239. enum {
  1240.     kHubLocalPowerStatus        = 1,
  1241.     kHubOverCurrentIndicator    = 2,
  1242.     kHubLocalPowerStatusChange    = 1,
  1243.     kHubOverCurrentIndicatorChange = 2
  1244. };
  1245.  
  1246. enum {
  1247.     off                            = false,
  1248.     on                            = true
  1249. };
  1250.  
  1251.  
  1252.  
  1253. struct hubDescriptor {
  1254.                                                                 /* See usbDoc pg 250?? */
  1255.     UInt8                             dummy;                        /* to align charcteristics */
  1256.  
  1257.     UInt8                             length;
  1258.     UInt8                             hubType;
  1259.     UInt8                             numPorts;
  1260.  
  1261.     UInt16                             characteristics;
  1262.     UInt8                             powerOnToGood;                /* Port settling time, in 2ms */
  1263.     UInt8                             hubCurrent;
  1264.  
  1265.                                                                 /* These are received packed, will have to be unpacked */
  1266.     UInt8                             removablePortFlags[8];
  1267.     UInt8                             pwrCtlPortFlags[8];
  1268. };
  1269. typedef struct hubDescriptor            hubDescriptor;
  1270.  
  1271.  
  1272.  
  1273. #if PRAGMA_STRUCT_ALIGN
  1274.     #pragma options align=reset
  1275. #elif PRAGMA_STRUCT_PACKPUSH
  1276.     #pragma pack(pop)
  1277. #elif PRAGMA_STRUCT_PACK
  1278.     #pragma pack()
  1279. #endif
  1280.  
  1281. #ifdef PRAGMA_IMPORT_OFF
  1282. #pragma import off
  1283. #elif PRAGMA_IMPORT
  1284. #pragma import reset
  1285. #endif
  1286.  
  1287. #ifdef __cplusplus
  1288. }
  1289. #endif
  1290.  
  1291. #endif /* __USB__ */
  1292.  
  1293.